Let's take a look at why it's important to monitor
your application. What resources you
should monitor, and how you should go
about troubleshooting performance for your application. When you monitor your
application and gather metrics, you can make improvements to the design of your application, increase reliability, detect
and fix security issues, and reduce usage costs
based on usage patterns. Monitor to analyze
long-term trends and answer questions such as, how fast is my database growing? How many users have I added in the last four
quarters, and so on. For example, is the size
lower than it was last week? Our requests served faster with Apache or NGINIX web server? Monitor to raise alerts
when something is broken and should
be fixed urgently, or something is about to be broken and can be
addressed preemptively. Monitor to perform ad hoc
retrospective analysis. For example, the latency of your application just
increased sharply. What else happened
around the same time? Identify APIs and resources
that you want to monitor. For example, there
might be public and private endpoints that
you want to monitor. Or multi-cloud resources such as Compute Engine VM instances, Cloud Storage buckets,
Amazon EC2 instances, and databases that you
want to keep your eye on. Here, we begin to touch on Google's Site Reliability
Engineering or SRE principles. I strongly urge you to check out Google's SRE book online. It's available for free. A service level indicator, or SLI, is a quantitative measure of some aspect of a service. A service level
indicator might be a predefined metric
or custom metric, such as log space metric. A service level
objective, or SLO, is a target value or range of
values for a service level. Service level objectives should include tolerance for
small variations. Absolute limits will result in noisy pages and require you to constantly
tweak thresholds. For example, latency is a
service level indicator. You can set a service
level objective indicating that 99 percent of requests over 30 days have latency less than
100 milliseconds. This is a great example of a service level objective that has a range of values
for a service level. After you identify the
resources to monitor and define service level
indicators and objectives, you can create dashboards to view metrics for
your application. Create dashboards that include
the four golden signals. Latency, traffic,
errors and saturation. Latency is the amount of time it takes to serve a request. Make sure to distinguish
between the latency of successful and
unsuccessful requests. For example, an HTTP error
that occurs due to a loss of connection to a database or other backend service might
be solved really quickly. However, because
an HTTP 500 error indicates a failed request, including 500 errors in your overall latency might
result in misleading metrics. Traffic is a measure of how much demand is
placed on your system. It is measured as a
system specific metric. For example, web server
traffic is measured as the number of HTTP or
HTTP requests per second. Traffic to a NoSQL database is measured as the number of read or write operations per second. Errors indicate the number
of failed requests. Criteria for failure might be anything like an explicit error, such as an HTTP 500 error or a successful HTTP 200 response but with incorrect content. It might also be a policy Error. For example, your application promises a response
time of one second, but some requests
take over a second. Saturation indicates how
full your application is or what resources are being stretched in reaching
target capacity. Systems can degraded performance before they achieve a
100 percent utilization. So make sure to set
utilization targets carefully.